'''
案例个人名片管理
[{},
{},
{}...]
'''

print("名片管理系统，请输入操作：")
print("1 :添加一个名片")
print("2 :删除一个名片")
print("3 :修改一个名片")
print("4 :查询一个名片")
print("5 :显示所有名片信息")
print("6 :退出系统\n")

cards = [{"name":"王先生","age":25,"addr":"重庆"},
         {"name":"赵女士","age":26,"addr":"成都"},
         {"name":"红鲤","age":36,"addr":"湖南"}]
while True:
    #获取用户输入操作
    print()
    num = int(input("请输入序号: "))
    print()

    if num==1:
        #添加名片，name,age,addr等信息
        card = {}
        name = input("请输入名称: ")
        age = input("请输入年龄: ")
        addr = input("请输入地址: ")
        card["name"] =name
        card["age"] = age
        card["addr"] = addr
        cards.append(card)

    elif num==2:
        #删除
        for l in cards:
            print(l)
        de = int(input("你要删除第几个名片："))
        del cards[de-1]
        print(cards)

    elif num==3:
        #修改名片
        for l in cards:
            print(l)
        de = int(input("你要修改第几个名片："))
        name = input("请输入名称: ")
        age = input("请输入年龄: ")
        addr = input("请输入地址: ")
        cards[de-1]["name"] = name
        cards[de-1]["age"] = age
        cards[de-1]["addr"] =addr
        print("修改结果：",cards[de])

    elif num==4:
        #查询一个
        for l in cards:
            print(l)
        de = int(input("你要查询第几个名片："))
        print(cards[de-1])

    elif num==5:
        #显示所有
        print("-----------名片信息如下-----------")
        print("姓名\t\t\t\t年龄\t\t\t\t地址")
        for l in cards:
            print(l["name"],"\t\t\t",l["age"],"\t\t",l["addr"])

    elif num==6:
        break

    else:
        print("输入错误请重新输入！！！")

# print(cards)










